package com.polaris.live.adapter.home

import androidx.recyclerview.widget.LinearLayoutManager
import com.chad.library.adapter.base.listener.OnItemClickListener
import com.polaris.live.common.adapter.BaseBindingAdapter
import com.polaris.live.common.adapter.VBViewHolder
import com.polaris.live.common.util.AppCodeUtils
import com.polaris.live.databinding.AdapterFriendRegionBinding
import com.polaris.live.resp.back_resp.RegionDataResp

/**
 * 区域选择
 *
 * @author Created by 半仙 on 2024/11/26/026 10:41
 */
class FriendShipRegionSelectAdapter :
    BaseBindingAdapter<AdapterFriendRegionBinding, RegionDataResp>() {

    private val regionAdapter = FriendShipRegionAdapter()

    override fun convert(holder: VBViewHolder<AdapterFriendRegionBinding>, item: RegionDataResp) {
        if (regionAdapter.data.isEmpty()) {
            holder.vb.apply {
                regionRecycler.apply {
                    adapter = regionAdapter.apply {
                        setDefualt(item)
                        setList(item.regions)
                    }
                    layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)
                    itemAnimator = null
                }
                if (AppCodeUtils.isAR()) {
                    backBg.scaleX = -1f
                    backImg.scaleX = -1f
                }
            }
        }
    }

    fun setOnRegionClickListener(l: OnItemClickListener) {
        regionAdapter.setOnItemClickListener(l)
    }

    fun getSelect() = regionAdapter.getSelectData()
}